<#import "/macro.ftl" as m>
<@m.page_header title='后台' />
<div id="page-content-wrapper">

    <div id="page-title">

        <h3>
            IOS端消息推送列表
        </h3>
        <div id="breadcrumb-right">
            <div class="float-right">
                <a href="javascript:;" class="btn medium primary-bg" onclick="showPushMessage();">
                    <span class="button-content">
                    <i class="glyph-icon icon-cog float-left"></i>
                    推送消息
                    </span>
                </a>

            </div>
        </div>
    </div>

    <div id="page-content">
        <table class="table" id="message_table">
            <thead>
            <tr>
                <th>推送消息</th>
                <th>发送模式</th>
                <th>推送时间</th>
                <th>提交时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <#list pager.list as messages>
            <tr>
                <td class="center">
                ${messages.alert}
                </td>
                <td>
                    <#if messages.productionMode == "true">
                        正式模式
                    </#if>
                    <#if messages.productionMode == "false">
                        测试模式
                    </#if>
                </td>
                <td>${(messages.pushTime?string('yyyy-MM-dd HH:mm'))!'-'}</td>
                <td>${(messages.submitTime?string('yyyy-MM-dd HH:mm'))!'-'}</td>
                <td>
                	<a href="javascript:;" class="btn medium primary-bg" onclick="deletemessage(${messages.id});">
                        <span class="button-content">删除</span>
                    </a>
                </td>
            </tr>
            </#list>
            </tbody>
        </table>
        <div class="button-group center-div">
        <#if (pager.pageNumber > 1)>
            <a href="/pushMessage/ios?pageNumber=${pager.pageNumber - 1}" class="btn large bg-white">
                <i class="glyph-icon icon-chevron-left"></i>
            </a>
        </#if>

        <a href="javascript;;" class="btn large disabled bg-gray">
            ${pager.pageNumber}
        </a>

        <#if (pager.pageNumber < pager.pageCount)>
            <a href="/pushMessage/ios?pageNumber=${pager.pageNumber + 1}" class="btn large bg-white">
                <i class="glyph-icon icon-chevron-right"></i>
            </a>
        </#if>
        </div>
    </div>
</div>

<div id="dialog-push-message" class="hide">
    <form id="form-add-presale" action="/pushMessage/push" method="post" class="mrg10A">
        <div class="form-row">
            <div class="form-input col-md-12">
                <textarea placeholder="推送内容" name="alert" data-required="true" data-rangelength="[1,70]" class="parsley-validated"></textarea>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-4">
                        <label for="">推送平台:</label>
                    </div>
                    <div class="form-input col-md-8">
                        <select name="models">
                            <option value="ios">iOS</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-4">
                        <label for="">推送时间:</label>
                    </div>
                    <div class="form-input col-md-8">
                        <input placeholder="不填立即推送" type="text" name="pushTime" class="parsley-validated" onclick="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-row">
                    <div class="form-label col-md-2">
                        <label for="">打开网页:</label>
                    </div>
                    <div class="form-input col-md-10">
                        <input placeholder="填写网页URL" type="text" name="openUrl" class="parsley-validated">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-4">
                        <label for="">打开App:</label>
                    </div>
                    <div class="form-input col-md-8">
                        <select name="openAppPage">
                            <option value="">选择打开App页面</option>
                            <option value="Message">消息</option>
                            <option value="Announcement">公告</option>
                            <option value="Home">首页</option>
                            <option value="Product">理财产品</option>
                            <option value="MyAsset">我的资产</option>
                            <option value="MyBonus">我的红包</option>
                            <option value="More">更多</option>
                            <option value="AboutHejia">关于快聚财</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-4">
                        <label for="">推送模式:</label>
                    </div>
                    <div class="form-input col-md-8">
                        <select size="1" name="productionMode" aria-controls="exp">
                        	<option value="false">测试模式</option>
                            <option value="true">正式模式</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<script language="javascript">
    function showPushMessage(){
        var html = '<div id="dialog" class="hide" title="消息推送">' + $("#dialog-push-message").html() + '</div>';
        $( html ).dialog({
            resizable:!0,
            minWidth:600,
            minHeight:350,
            modal:!0,
            dialogClass:"modal-dialog",
            closeOnEscape:!0,
            close : function() {
                $( this ).dialog( "destroy" );
            },
            buttons: {
                推送: function() {
                    var valid = $('#dialog form').parsley( 'validate' );
                    if(!valid){
                        return;
                    }

                    $.post( '/pushMessage/push', $( '#dialog form' ).serialize() )
                            .done(function(data){
                                if(data.result == "success"){
                                    $.jGrowl("推送成功", {sticky:!1,position:"top-right",theme:"bg-green"});

                                    var tr = '<tr><td>' + data.pushMessage.alert + '</td>' +
                                            '<td>' + (data.pushMessage.productionMode == "true" ? "正式模式" : "测试模式") + '</td>' +
                                            '<td>' + new Date(data.pushMessage.createDate).Format('yyyy-MM-dd hh:mm:ss') + '</td>' +
                                            '</tr>';
                                    $("#message_table tr:eq(0)").after(tr);

                                }else{
                                    $.jGrowl("发送失败！错误代码："+data.status, {sticky:!1,position:"top-right",theme:"bg-red"});
                                }
                                $( "#dialog" ).dialog( "close" );
                            })
                            .fail(function(){
                                $.jGrowl("推送失败", {sticky:!1,position:"top-right",theme:"bg-green"});
                                $( "#dialog" ).dialog( "close" );
                            });
                }
            }
        });
    };
    
    
$(document).ready(function() {
	<#if msg!=null>
	$.jGrowl("${msg}", {sticky:!1,position:'bottom-right',theme:'bg-green'});
	</#if>
});    
    
function deletemessage(id){
		$.messager.confirm("提示", "确认删除该消息吗？", function() { 
			location.href="/pushMessage/delete/"+id;
		});
}
</script>